package com.itheima.edu.info.manager.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class AgeUtil {
    //构造方法私有化
    private AgeUtil() {
    }

    //2.成员静态化
        public static String getAge(String birthday){
            long age = 0;
            try {
                //根据用户输入的出生日期，自动计算年龄
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date birthdayDate = sdf.parse(birthday);
                //获取当前时间
                Date nowDate = new Date();
                //计算两个日期之间时间差值（对应的年）
                age = (nowDate.getTime() - birthdayDate.getTime()) / 1000L / 60 / 60 / 24 / 365;
            } catch (Exception e) {
            }
            return age + "";
        }



}
